let _animationCloud;
let _cloudNum = 0
let _isStop = false
let _cloudElem;

export const initCloud = (cloudElem) => {
  _cloudElem = cloudElem
}

const isStoped = () => {
  return _isStop;
}

export const startCloud = (cb) => {
  const keyframes = [
    {
      transformOrigin: "50% 50%",
      time: 0,
      transform: {
        translateX: 20,
      },
    },
    {
      transformOrigin: "50% 50%",
      time: 100,
      transform: {
        translateX: -580,
      },
    }
  ]
  const options = {
    duration: 15000,
    easing: 'linear',
    delay: 300,
    // fill: 'forwards'
  }
  _animationCloud = _cloudElem.animate(keyframes, options)

  _animationCloud.onfinish = () => {
    if (!isStoped()) {
      cb(_cloudNum)
      _cloudNum++
      startCloud(cb)
    }
  }
  _animationCloud.play()
  _isStop = false
}

export const endCloud = () => {
  _isStop = true
  _animationCloud.finish()
}


